<template>
  <div class="about">
    <h1>{{ id ? "编辑" : "创建" }}账户</h1>
    <el-form @submit.native.prevent="save">
      <el-form-item label="用户名">
      <el-input v-model="model.username" placeholder="请输入用户名"></el-input></el-form-item>

      <el-form-item label="密码">
      <el-input v-model="model.password" show-password :placeholder='id? "请输入新密码":"请输入密码"' ></el-input></el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit">{{id? "保存":"提交"}}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "AdminUsersEdit",
  props: {
    id: {},
  },
  data() {
    return {
      model: {},
    };
  },
  methods: {
    async save() {
      let res
      if (this.id) {
        res =await this.$http1.put(`rest/adminusers/${this.id}`,this.model)
      }
      else {
        res = await this.$http1.post("rest/adminusers", this.model);
      }
        console.log(res);
        this.$router.push("/adminusers/list");
        this.$message({ type: "success", message: "保存成功" });
    },
    async fech() {
      const res = await this.$http1.get(`rest/adminusers/${this.id}`);
      this.model = res.data;
    },
  },
  created() {
    this.id && this.fech();
  },
};
</script>

<style>
</style>